<!DOCTYPE html>
<html>
<head>
    <title>垃圾分类科普知识 - 垃圾分类系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
        }
        
        .header {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 20px 30px;
            margin-bottom: 30px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }
        
        .header h1 {
            color: #2d3748;
            font-size: 28px;
            font-weight: 700;
            display: flex;
            align-items: center;
            gap: 12px;
        }
        
        .header-actions {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
        }
        
        .btn {
            padding: 10px 20px;
            border: none;
            border-radius: 10px;
            font-size: 14px;
            font-weight: 600;
            cursor: pointer;
            text-decoration: none;
            transition: all 0.3s ease;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        
        .btn-primary {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
        }
        
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
        }
        
        .btn-success {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
            color: white;
        }
        
        .btn-success:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);
        }
        
        .page-title {
            color: white;
            font-size: 32px;
            font-weight: 700;
            margin-bottom: 30px;
            text-align: center;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        
        .filter-section {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 16px;
            padding: 20px;
            margin-bottom: 30px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        
        .filter-tabs {
            display: flex;
            gap: 8px;
            flex-wrap: wrap;
            justify-content: center;
        }
        
        .filter-tab {
            padding: 10px 20px;
            border-radius: 25px;
            text-decoration: none;
            color: #6b7280;
            font-weight: 500;
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .filter-tab.active {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
        }
        
        .filter-tab:hover:not(.active) {
            background: rgba(102, 126, 234, 0.1);
            color: #667eea;
            border-color: #667eea;
        }
        
        .articles-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
            gap: 25px;
            margin-bottom: 30px;
        }
        
        .article-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border-radius: 20px;
            padding: 25px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
            cursor: pointer;
            animation: slideUp 0.6s ease-out;
        }
        
        .article-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
        }
        
        @keyframes slideUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .article-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 15px;
        }
        
        .article-title {
            font-size: 18px;
            font-weight: 700;
            color: #2d3748;
            margin-bottom: 8px;
            line-height: 1.4;
        }
        
        .category-badge {
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 12px;
            font-weight: 600;
            color: white;
            white-space: nowrap;
        }
        
        .category-recyclable {
            background: linear-gradient(135deg, #10b981 0%, #059669 100%);
        }
        
        .category-harmful {
            background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
        }
        
        .category-kitchen {
            background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
        }
        
        .category-other {
            background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
        }
        
        .category-knowledge {
            background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
        }
        
        .category-environment {
            background: linear-gradient(135deg, #059669 0%, #047857 100%);
        }
        
        .article-content {
            color: #6b7280;
            line-height: 1.6;
            margin-bottom: 15px;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        
        .article-footer {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 14px;
            color: #9ca3af;
        }
        
        .article-meta {
            display: flex;
            gap: 15px;
        }
        
        .read-more {
            color: #667eea;
            font-weight: 600;
            text-decoration: none;
            transition: color 0.3s ease;
        }
        
        .read-more:hover {
            color: #5a67d8;
        }
        
        .empty-state {
            text-align: center;
            padding: 60px 20px;
            color: white;
        }
        
        .empty-state h3 {
            font-size: 24px;
            margin-bottom: 10px;
        }
        
        .empty-state p {
            font-size: 16px;
            opacity: 0.8;
        }
        
        @media (max-width: 768px) {
            .header {
                flex-direction: column;
                gap: 16px;
                text-align: center;
            }
            
            .header-actions {
                justify-content: center;
            }
            
            .page-title {
                font-size: 24px;
            }
            
            .articles-grid {
                grid-template-columns: 1fr;
                gap: 20px;
            }
            
            .article-card {
                padding: 20px;
            }
            
            .filter-tabs {
                justify-content: flex-start;
                overflow-x: auto;
                padding-bottom: 10px;
            }
            
            .filter-tab {
                white-space: nowrap;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <header class="header">
            <h1>📚 垃圾分类科普知识</h1>
            <div class="header-actions">
                <a href="/" class="btn btn-primary">🏠 返回首页</a>
                {% if session.user_id %}
                    <a href="/logout" class="btn btn-success">🚪 注销</a>
                {% else %}
                    <a href="/login" class="btn btn-success">🔑 登录</a>
                {% endif %}
            </div>
        </header>
        
        <h1 class="page-title">📚 垃圾分类科普知识</h1>
        
        <div class="filter-section">
            <div class="filter-tabs">
                <a href="/knowledge" class="filter-tab {{ 'active' if not selected_category }}">🌟 全部</a>
                <a href="/knowledge?category=可回收垃圾" class="filter-tab {{ 'active' if selected_category == '可回收垃圾' }}">♻️ 可回收垃圾</a>
                <a href="/knowledge?category=有害垃圾" class="filter-tab {{ 'active' if selected_category == '有害垃圾' }}">☠️ 有害垃圾</a>
                <a href="/knowledge?category=厨余垃圾" class="filter-tab {{ 'active' if selected_category == '厨余垃圾' }}">🍎 厨余垃圾</a>
                <a href="/knowledge?category=其他垃圾" class="filter-tab {{ 'active' if selected_category == '其他垃圾' }}">🗑️ 其他垃圾</a>
                <a href="/knowledge?category=垃圾分类知识" class="filter-tab {{ 'active' if selected_category == '垃圾分类知识' }}">📚 分类知识</a>
                <a href="/knowledge?category=环保知识" class="filter-tab {{ 'active' if selected_category == '环保知识' }}">🌱 环保知识</a>
            </div>
        </div>
        
        {% if articles %}
            <div class="articles-grid">
                {% for article in articles %}
                <div class="article-card" onclick="window.location.href='/knowledge/{{ article.id }}'">
                    <div class="article-header">
                        <div>
                            <h3 class="article-title">{{ article.title }}</h3>
                        </div>
                        <span class="category-badge 
                            {% if article.category == '可回收垃圾' %}category-recyclable
                            {% elif article.category == '有害垃圾' %}category-harmful
                            {% elif article.category == '厨余垃圾' %}category-kitchen
                            {% elif article.category == '其他垃圾' %}category-other
                            {% elif article.category == '环保知识' %}category-environment
                            {% else %}category-knowledge{% endif %}">
                            {{ article.category }}
                        </span>
                    </div>
                    
                    <div class="article-content">
                        {{ article.content[:150] }}{% if article.content|length > 150 %}...{% endif %}
                    </div>
                    
                    <div class="article-footer">
                        <div class="article-meta">
                            <span>👁️ {{ article.view_count }}</span>
                            <span>📅 {{ article.created_at.strftime('%m-%d') }}</span>
                        </div>
                        <a href="/knowledge/{{ article.id }}" class="read-more">阅读全文 →</a>
                    </div>
                </div>
                {% endfor %}
            </div>
        {% else %}
            <div class="empty-state">
                <h3>📝 暂无科普文章</h3>
                <p>{% if selected_category %}该分类下暂无文章{% else %}还没有发布任何科普文章{% endif %}</p>
            </div>
        {% endif %}
    </div>
</body>
</html>